package com.migu.jdbc

import java.sql.{Connection, PreparedStatement, SQLException}

/**
  * Created by maguoyun on 2017/03/22.
  */
object OnlineJdbc {
  private val dao: OnlineJdbc = new OnlineJdbc()

  def apply: OnlineJdbc = dao
}

class OnlineJdbc private extends Serializable {
  /**
   * table_name:
   * 字段：类型和名称
   */
  @transient val insertOnlinePeopleSql = "insert into t_online_user(time_cycle,uid,channel_id,ou,insert_time)" +
  "values(?,?,?,?,now())"

  def insertOu(tc: String, uid: String, ci: String, ou: Int): Unit = {
    var conn: Connection = null
    var ps: PreparedStatement = null
    try {
      conn = JdbcUtil.getConn()
      ps = conn.prepareStatement(insertOnlinePeopleSql)
      ps.setString(1, tc)
      ps.setString(2, uid)
      ps.setInt(3, ci.toInt)
      ps.setInt(4, ou)
      ps.executeUpdate
    } catch {
      case e: SQLException =>
        System.out.println("insertOu mysql error ... " + e.getMessage)
    } finally {
      if (ps != null) ps.close()
      if (conn != null) conn.close()
    }
  }
}
